ALTER PROCEDURE [dbo].[Proc_S5_SyncResultTo44_A00014]
As
/***************************************************
  Program_Name: Proc_S5_SyncResultTo44_A00014
  Program_Desc: 水务预通知将结果同步回44服务器
  Commentary:上海过河兵
  Revision: V1.0
  Author: Tao
  Date: 2019-09-02
***************************************************/

Begin
  
  declare @count int
  declare @sms_guid varchar(36)
  declare @ResultInfo varchar(1024)
  
  Select @Count = Count(*) From Ucis_Data_To_44 Where Type_Id = 'A00014' AND datetime >= '2020-06-20' 
  
  if @COUNT>0
    Begin
      
      --获取催缴计划
      Select Top 1 @Sms_Guid = Sms_Guid
        From Ucis_Data_To_44
       Where Type_Id = 'A00014' AND datetime >= '2020-06-20' order by datetime desc
       
      if @sms_guid!=''
        Begin Try

            Insert Into Openquery
              (Ucis115,
               'SELECT nf, yf, yhbh, tqje, yhbm, yhzh,lxdh, ysdz, sjhm, tqlx, tqrq1,
            tqrq2, tqsf, tqpsf, tqljf, id, tel_1, tel_2, tel1status, tel2status, smsstatus, DOC_GUID, CJ_GUID, type_id,
             ob_comment, sms_comment, t_result, t_result1, ob_comment1, ob_file, ob_file1, ob_result, ob_result1,
            KTY_SelSmsstatus, KTY_SelTelStatus, sms_sendtime, sms_guid, tel1_endtime, tel2_endtime, createdate, itemid, deptcode from ucis.CJ_Comprehensive')
              Select Nf,
                     Yf,
                     Yhbh,
                     Tqje,
                     Yhbm,
                     Yhzh,
                     Lxdh,
                     Ysdz,
                     Sjhm,
                     Tqlx,
                     Tqrq1,
                     Tqrq2,
                     Tqsf,
                     Tqpsf,
                     Tqljf,
                     Id,
                     Tel_1,
                     Tel_2,
                     Tel1status,
                     Tel2status,
                     Smsstatus,
                     Doc_Guid,
                     Cj_Guid,
                     Type_Id,
                     Ob_Comment,
                     Sms_Comment,
                     t_Result,
                     t_Result1,
                     Ob_Comment1,
                     Ob_File,
                     Ob_File1,
                     Ob_Result,
                     Ob_Result1,
                     Kty_Selsmsstatus,
                     Kty_Seltelstatus,
                     Sms_Sendtime,
                     Sms_Guid,
                     Tel1_Endtime,
                     Tel2_Endtime,
                     Createdate,
                     Itemid,
                     Deptcode
                From Cj_Comprehensive_Ucis
               Where Sms_Guid = @Sms_Guid
                 And Yhbh Is Not Null;

            Insert Into Openquery
              (Ucis115, 'SELECT * from ucis.Cj_Updatetype')
              (Guid, Typeid, Dbtype, Intime)
            Values
              (@Sms_Guid, 'A00014', 1, Getdate());

            Delete Ucis_Data_To_44
             Where Type_Id = 'A00014'
               And Sms_Guid = @Sms_Guid;


        End Try

				Begin Catch

					Set @ResultInfo = 'Proc_S5_SyncResultTo44_A00014 Sms_Guid:' + @Sms_Guid
					Exec Proc_Error_Record @ResultInfo

				End Catch
      
    End
  
End